package ch07_GUI编程;


import javax.swing.*;
import java.awt.*;

public class JPopupMenuDemo {
	public static void main(String[] args) {
		BaseFrame f = new BaseFrame("JPopupMenu Demo");
		JTextField tf = new JTextField("带鼠标右键弹出菜单的文本框…");
		tf.setComponentPopupMenu(createPopupMenu());

		f.setLayout(new FlowLayout());
		f.add(tf);
		f.showMe();
	}
	//创建弹出菜单
	private static JPopupMenu createPopupMenu(){
		String[] ts = {"剪切","粘贴","复制","删除",null,"全选"};
		JPopupMenu pm = new JPopupMenu();

		for (String t : ts) {
			if(t!=null) {
				pm.add(new JMenuItem(t));
			}else {
				pm.addSeparator();
			}
		}
		pm.setPopupSize(80,120);
		return pm;
	}
}
